package com.baselibrary.libs.Utils.UtilsView;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.RelativeLayout;

/**
 * Created by Administrator 于萌萌
 * 创建日期: 11:39 . 2017年03月20日
 * 描述:
 * <p>
 * <p>
 * 备注:
 */

public class UtilsView {


    public static void setViewSize(Context context, View view, int height,int width){
        double reviseHeight = -1;
        double reviseWidth = -1;
        reviseHeight = NumCheck.getcheck(height);
        reviseWidth = NumCheck.getcheck(width);

      //  reviseHeight/100;
        int dmHeight = -1;
        int dmWidth = -1;
        DisplayMetrics dm = context.getResources().getDisplayMetrics();
       // RelativeLayout.LayoutParams mParams;
        dmHeight = dm.heightPixels;
        dmWidth = dm.widthPixels;
        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams)view.getLayoutParams();
        layoutParams.height = (int) (dmHeight * reviseHeight/100 + 0.5f);

//        mParams = new RelativeLayout.LayoutParams(
//                RelativeLayout.LayoutParams.MATCH_PARENT,
//                (int) (dmHeight * reviseHeight/100 + 0.5f));

        view.setLayoutParams(layoutParams);

    }



    public  static  class NumCheck{
        static  int num;
        static  int numMax;
        static int numMin;
        static double getNum =-1;


        public NumCheck setNum(int num){
            this.num = num;
            return this;
        }
        public NumCheck setNumMax(int numMax){
            this.numMax = numMax;
            return this;
        }


        public NumCheck setNumMin(int numMin){
            this.numMin = numMin;
            return this;
        }

        private static double getcheck(int num) {

            if (numMax == 0){
                numMax = 100;
            }
            if (numMin == 0){
                numMin = 50;
            }
            if (num<numMin||num>numMax){
                if (num<numMin){
                    getNum = 50;
                }
                if (num>100){
                    getNum = 100;
                }
            }

            if (-1 == getNum){
                getNum = num;
            }
            return getNum;
        }
    }
}
